<?php

namespace app\common\library\ai;

use app\common\model\vip\Record as VipRecordModel;
use app\admin\model\ai\vip\Log as VipLogModel;


// use app\common\facade\ai\UserVip;
class UserVip
{
    /**
     * 判断是否为会员
     */
    public function isVip($user_id): bool
    {
        $vipRecord = VipRecordModel::where('user_id', $user_id)->find();
        if ($vipRecord && $vipRecord->end_time > time()) {
            return true;
        }
        return false;
    }

    /**
     * 增加消耗记录
     */
    public function addRecord($user_id, $type = 'chat', $num = 1, $remark = '消耗次数'): bool
    {
        VipLogModel::create([
            'user_id' => $user_id,
            'type' => $type,
            'num' => $num,
            'remark' => $remark,
            'create_time' => time(),
        ]);
        return true;
    }
}